﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;

namespace PMSSys
{
    class bmaController
    {
        private DBconnentor dbConnect;
        public DBconnentor DbConnect
        {
            set { dbConnect = value; }
            get { return dbConnect; }
        }
        
        public bool addBma(BMA bma)
        {
            MySqlCommand query = new MySqlCommand("INSERT INTO bm_anal(p_id, bma_date, clinicalabstract, reviewofformat, report, interpretation)" + 
                "VALUES(@P_ID, @BMA_DATE, @CLINICALABSTRACT, @REVIEWOFSMEAR, @REPORT, @INTERPRETATION)", dbConnect.getConnection());

            query.Parameters.Add(new MySqlParameter("@P_ID", MySqlDbType.Int32)).Value = bma.PatientID;
            query.Parameters.Add(new MySqlParameter("@BMA_DATE", MySqlDbType.DateTime)).Value = bma.BmaDate;
            query.Parameters.Add(new MySqlParameter("@CLINICALABSTRACT", MySqlDbType.String)).Value = bma.ClinAbst;
            query.Parameters.Add(new MySqlParameter("@REVIEWOFSMEAR", MySqlDbType.String)).Value = bma.RevPRS;
            query.Parameters.Add(new MySqlParameter("@REPORT", MySqlDbType.String)).Value = bma.RepBSTR;
            query.Parameters.Add(new MySqlParameter("@INTERPRETATION", MySqlDbType.String)).Value = bma.Interpretation;

            return dbConnect.nonQueryExecute(query);
        }
        public DataTable getBMADataTable(int p_id)
        {
            string str = "SELECT bma_id, bma_date as `Date Issued` FROM bm_anal WHERE p_id = " + p_id.ToString();
            return dbConnect.view(str);
        }
        public bool updateBma(BMA bma)
        {
            MySqlCommand query = new MySqlCommand(@"UPDATE bm_anal SET p_id = @P_ID, bma_date = @BMA_DATE, clinicalabstract = @CLINICALABSTRACT, reviewofformat = @REVIEWOFFORMAT, 
            report = @REPORT, interpretation = @INTERPRETATION", dbConnect.getConnection());

            query.Parameters.Add(new MySqlParameter("@P_ID", MySqlDbType.Int32)).Value = bma.PatientID;
            query.Parameters.Add(new MySqlParameter("@BMA_DATE", MySqlDbType.DateTime)).Value = bma.BmaDate;
            query.Parameters.Add(new MySqlParameter("@CLINICALABSTRACT", MySqlDbType.String)).Value = bma.ClinAbst;
            query.Parameters.Add(new MySqlParameter("@REVIEWOFSMEAR", MySqlDbType.String)).Value = bma.RevPRS;
            query.Parameters.Add(new MySqlParameter("@REPORT", MySqlDbType.String)).Value = bma.RepBSTR;
            query.Parameters.Add(new MySqlParameter("@INTERPRETATION", MySqlDbType.String)).Value = bma.Interpretation;
            
            return dbConnect.nonQueryExecute(query);
        }
    }
}
